package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.AttendanceClassData;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2016年 12月 05日
 * Time: 下午1:49
 *
 * @QQ : 1234567890
 * **********************************
 */
public class SubDialogListAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<AttendanceClassData> mData;

    public SubDialogListAdapter(Context mContext, ArrayList<AttendanceClassData> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData == null ? 0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        AttendanceClassData classData = mData.get(position);
        if (convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.sub_dialog_item_layout,null);
            holder.textView = (TextView) convertView.findViewById(R.id.tv_sub_dialog_item);
            convertView.setTag(holder);
        }  else{
            holder = (ViewHolder) convertView.getTag();
        }
        String title = "";
        if (classData.getIs_quartic() == 0){
            title = classData.getSub_name() + "  " + classData.getStart_work_time() + "    " + checkTime(classData.getEnd_work_time());
        } else if (classData.getIs_quartic() == 1){
            if (classData.getNoon_end_time().contains("-")){
                title = classData.getSub_name() + "  " + classData.getStart_work_time() + " - " + checkTime(classData.getNoon_end_time()) + "\n" +checkTime(classData.getNoon_start_time()) + " - " +checkTime(classData.getEnd_work_time());
            } else{
                title = classData.getSub_name() + "  " + classData.getStart_work_time() + " - " + checkTime(classData.getNoon_end_time()) + "  " +checkTime(classData.getNoon_start_time()) + " - " +checkTime(classData.getEnd_work_time());
            }
        } else if (classData.getIs_quartic() == -1){
            title = "休息";
        }
        holder.textView.setText(title);
        return convertView;
    }

    private String checkTime(String time){
        if (time.contains("-")){
            return time.replace("-","次日");
        }else{
            return time;
        }
    }

    class ViewHolder{
        TextView textView;
    }
}
